using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.XPath;
using System.Text;

namespace Atom.Core
{
  public class AtomMediaConstruct : AtomElement
  {

    private Dictionary<string,string> attributes;

    public Dictionary<string,string> Attributes
    {
      get { return attributes; }
      set { attributes = value; }
    }

    private string text;

    public string Text
    {
      get { return text; }
      set { text = value; }
    }

    #region XPath parsing stuff
    internal static AtomMediaConstruct Parse(XPathNavigator navigator)
    {
     
      AtomMediaConstruct dateElement = new AtomMediaConstruct();
      //string temp = String.Empty;
      dateElement.Attributes = new Dictionary<string, string>();
      XPathNavigator nav = navigator.Clone();
      XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element, true);
      while (iter.MoveNext())
      {
        dateElement.Text = iter.Current.Value;
        switch (iter.Current.Name.ToLower())
        {
          case "link":
            try
            {
              dateElement.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
            }
            catch { }
            break;
        }
      }

      // select the attributes
      iter = nav.Select("@*");
      do
      {
        dateElement.Attributes.Add(iter.Current.Name.ToLower(), iter.Current.Value);
        //switch (iter.Current.Name.ToLower())
        //{
        //  case "rel":
        //    linkElement.Rel = Utils.Utils.ParseRelationship(iter.Current.Value);
        //    break;

        //  case "type":
        //    linkElement.Type = Utils.Utils.ParseMediaType(iter.Current.Value);
        //    break;

        //  case "href":
        //    linkElement.HRef = resolveUri(xmlBaseRootUri, iter.Current.Value);
        //    break;

        //  case "title":
        //    linkElement.Title = iter.Current.Value;
        //    break;
        //}
      } while (iter.MoveNext());


      return dateElement;
    }
    #endregion
  }
}
